<template>
  <div class="RankListDetail">
    <van-icon name="arrow-left" @click="goBack" />
    <div class="header">
      <img :src="rankData.info.picUrl" alt="#" />
      <h3>{{ rankData.info.title }}</h3>
      <h4>{{ rankData.info.titleDetail }}</h4>
      <span>{{ rankData.update }}</span>
    </div>
    <div class="content">
      <span class="content_num">排行榜共{{ rankData.total }}首</span>
      <ul>
        <li
          v-for="item in rankData.list"
          :key="item.songId"
          class="item"
          @click="selectSong(item)"
        >
          <div class="item_rank">
            <h4>{{ item.rank }}</h4>
            <h4>{{ item.rankValue }}</h4>
          </div>
          <div class="item_song">
            <h4>{{ item.title }}</h4>
            <span>{{ item.singerName }} {{ item.subtitle }}</span>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "RankListDetail",
  data() {
    return {
      rankData: "",
    };
  },
  created() {
    this.getData();
  },
  methods: {
    getData() {
      axios
        .get("/api/top", {
          params: {
            id: this.$route.params.id,
          },
        })
        .then((res) => {
          console.log(res.data.data);
          this.rankData = res.data.data;
        })
        .catch((err) => {
          console.error(err);
        });
    },
    goBack() {
      this.$router.go(-1);
    },
    selectSong(item) {
      const id = item.mid;
      this.$store.commit("setSinger", item);
      this.$router.push({ path: `/SongDetail/${id}` });
    },
  },
};
</script>

<style scoped>
.header {
  text-align: center;
}
.header img {
  width: 150px;
  height: 150px;
}
.content {
  margin-top: 10px;
}
.content_num {
  font-size: 10px;
  margin-left: 10px;
}

.item {
  display: flex;
  align-items: center;
  margin: 10px 0;
  border-top: 1px solid rgb(170, 170, 170);
  padding-top: 5px;
}
.item_rank {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 45px;
  margin: 0 10px;
}
.item_rank h4 {
  margin: 2px 0;
}
.item_song h4 {
  margin: 2px 0;
}
.van-icon {
  font-size: 30px;
}
</style>